package com.jincp.common.brvah.util;

import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.SimpleItemAnimator;

/**
 * Created by jinchunping on 2019/2/28.
 */

public class RecyclerViewUtil {

    /**
     * 关闭默认局部刷新动画
     *
     * 解决办法很简单，RecyclerView.setAdapter()之前调用
     */
    public static void closeDefaultAnimator(RecyclerView recyclerView) {
        if (recyclerView == null) return;
        if (recyclerView.getItemAnimator() instanceof SimpleItemAnimator) {
            recyclerView.getItemAnimator().setAddDuration(0);
            recyclerView.getItemAnimator().setChangeDuration(0);
            recyclerView.getItemAnimator().setMoveDuration(0);
            recyclerView.getItemAnimator().setRemoveDuration(0);
            ((SimpleItemAnimator) recyclerView.getItemAnimator()).setSupportsChangeAnimations(false);
        }
    }
}
